Question 1

sf_uscities = readr::read_csv("D:/LifeInUCSB/Study/GEOG176A/week2/assignment5/geog-176A-labs/data/uscities.csv") %>% 
  filter(city ==("Palo")) %>% 
  st_as_sf(coords = c("lng", "lat"), crs = 4326) %>%
  st_transform(5070) %>% 
  st_buffer(5000) %>% 
  st_bbox() %>% 
  st_as_sfc() %>% 
  st_as_sf()

Question 2-3

st = list.files("D:/LifeInUCSB/Study/GEOG176A/week2/assignment5/geog-176A-labs/data", full.names = TRUE, pattern = "TIF")

s = stack(st) %>% 
  setNames(c(paste0("band", 1:6)))


cropper = sf_uscities %>% 
  st_transform(crs(s))

r = crop(s, cropper)

#Step 3

#The dimensions is 7811 rows and 7681 columns, 6 layers. 
#The CRS is WGS84.
#The cell resolution is x=30, y=30 (meters). 

#Step 4
#The dimensions is 340 rows and 346 columns, 6 layers. 
#The CRS is WGS84.
#The cell resolution is x=30, y=30 (meters). 

Question 4

Q4.1

Q4.2

Question 5

## [1] 117640      6

Question 6

6.1

Total cells number of each plot
Number
NDVI 6666
NDWI 7212
MNDWI 11939
WRI 8469
SWI 15201
total area of the flooded cells/ m^2
Area
NDVI 5999400
NDWI 6490800
MNDWI 10745100
WRI 7622100
SWI 13680900

6.2

Extra credit

## [1] "-91.78945, 42.06308"
##      NDVI NDWI MNDWI WRI SWI layer
## [1,]    1    1     1   1   1     1

All of the six maps captured the flood in this location.